package com.example.administrator.szb.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.administrator.szb.R;
import com.example.administrator.szb.activity.base.BasePresenter;
import com.example.administrator.szb.activity.base.MVPBaseActivity;
import com.example.administrator.szb.http.URLAddress;
import com.example.administrator.szb.util.QTLog;
import com.example.administrator.szb.util.ScreenUtils;

public class Welcome2 extends MVPBaseActivity {
    ImageView image;
    TextView tiaoguo;
    View v_statusbar;
    private boolean tiao = false;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_welcome2);
        //ChangeStatuUtil.setTranslucentStatus(this);
    }

    @Override
    protected void setBarColor() {

    }

    @Override
    protected BasePresenter createPresenter() {
        return null;
    }

    @Override
    protected void initView() {
        v_statusbar = findViewById(R.id.v_statusbar);
        ViewGroup.LayoutParams params = v_statusbar.getLayoutParams();
        params.height = ScreenUtils.getStatusBarHeight(context);
        v_statusbar.setLayoutParams(params);
        tiaoguo = findViewById(R.id.tiaoguo);
        image = findViewById(R.id.image);
        String url = getIntent().getStringExtra("url");
        QTLog.e(URLAddress.HOST_PORT+url);
        Glide.with(context).load(URLAddress.HOST_PORT+url).into(image);

        tiaoguo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (!tiao){
                    goHome();
                }
            }
        });
    }
    private int i=3;
    private void mms(){
        image.postDelayed(new Runnable() {
            @Override
            public void run() {
                if (i<=0){
                    tiaoguo.setText("跳过 0");
                }else {
                    tiaoguo.setText("跳过 "+i+"");
                }

                if (i>=0||tiao){
                    i--;
                    mms();
                    return;
                }


                goHome();
            }
        },1000);
    }
    private void goHome(){
        if (tiao){
            return;
        }
        tiao = true;
        Intent intent = new Intent(context,HomeActivity.class);
        startActivity(intent);
    }
    @Override
    protected void initEvent() {

    }

    @Override
    protected void initData() {
        mms();
    }
}
